<template>
  <basic-container>
      <el-dialog :append-to-body="true" title="审计取证单" :before-close="cancelDialog" :close-on-click-modal="false"
                 :modal="false" :visible.sync="dialog" fullscreen custom-class="ledger" top="5vh">
        <el-form ref="optForm" :model="form" label-width="90px">
        <div class="title">基本信息</div>
          <el-row>
            <el-col :span="6">
              <el-form-item label-width="100px" label="项目名称:" prop="projectName" :rules="{required: true, message: '项目名称不能为空', trigger: ['focus', 'change']}">
                <el-input v-model="form.projectName" placeholder="项目名称" @focus="showProjectDialog()"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label-width="100px" label="疑点编号: " prop="pointCode" >
                <el-input v-model="form.pointCode" placeholder="选择疑点编号" @focus="showChoseDoubtful()" :readonly="true"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label-width="100px"  label="疑点描述:" prop="pointDesc">
                <el-input v-model="form.pointDesc" :autosize="{ minRows: 2}" type="textarea"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        <div class="title">基本信息</div>
          <el-row>
            <el-col>
              <el-form-item label-width="100px" label="审计事项:" prop="auditMatter">
                <el-input v-model="form.auditMatter" placeholder="审计事项" type="textarea" autosize ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label-width="100px" label="审计事项摘要:" prop="auditPurpose">
                <el-input v-model="form.auditMatterAbstract" placeholder="审计事项摘要" type="textarea" autosize ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label-width="100px" label="定性及依据:" prop="lawId">
                <el-input v-model="form.lawContent" type="textarea" placeholder="定性及依据" autosize style="width: 90%;"></el-input>
                <el-button @click="openLawFunction" type="primary" size="small">选择法律法规</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>

        <span slot="footer" class="dialog-footer">
        <el-button @click="cancelDialog" size="small" icon="el-icon-close">关闭</el-button>
        <el-button v-if="!isView" type="primary" @click="submit" size="small" icon="el-icon-check" :loading="loading">保存</el-button>
        <el-button v-if="!isView && (!form.status || form.status === 0 || form.status === 2)" type="primary" @click="submitAudit" size="small" icon="el-icon-check" :loading="loading">保存送审</el-button>

      </span>

      </el-dialog>
    <table-law :dialog="TableLawVisible" ref="dataLaw" @cancelDialog="closeLawDialog"></table-law>
    <ChoseProject :projectDialog="projectDialog" @cancelDialog="closeProjectDialog" @setValue="projectDataHandle" ref="ChoseProject"/>
    <ChoseDoubtful :choseDoubtful="choseDoubtful" @setValue="setChoseDoubtful" @closeDialog="closeChoseDoubtful" ref="choseDoubtful" />
  </basic-container>
</template>


<script>
import ChoseProject from "@/components/audited/ChoseProject.vue";
import {submitAudit, submit} from "@/api/adis/execute/evidence";
import WebDocument from "@/components/form/webDocument.vue";
import TableLaw from "@/components/table/lawList.vue";
import ChoseDoubtful from "@/components/audited/ChoseDoubtful.vue";

export default {
  components: {ChoseDoubtful, WebDocument, ChoseProject, TableLaw},
  // props: {
  //   dialog: Boolean,
  // },
  dictTypes: ['audit_type_1_sub'],
  data(){
    return{
      isHidden:true,
      dialog: false,
      loading: false,
      tableData:[{
        templateId : 1
      }],
      selectedRows: [],
      selectedRow: {},
      form:{},
      projectDialog:false,
      projectForm:{},
      isView:false,
      formDisplay:false,
      TableLawVisible: false,
      choseDoubtful:false,
      templateForm: [],
      Authorization: '',
      attachment:{},
      params: {},
    }
  },
  watch: {
  },
  created() {
    this.Authorization = 'Bearer ' + this.$store.getters.access_token
  },
  methods: {
    showChoseDoubtful(){
      this.$nextTick(() => {
        this.$refs.choseDoubtful.initParams({
          unUsePoint: true,//未使用的疑点
          isCreateEvidence: true,//用来创建取证单
          projectId: this.form.projectId,
        });
      })
    },
    closeChoseDoubtful(val){
      this.choseDoubtful= false;
    },
    setChoseDoubtful(data){
      this.choseDoubtful= false;
      // this.pointForm = data;
      // this.form = data;
      this.$set(this.form,'pointId',data.pointId);
      this.$set(this.form,'pointCode',data.pointCode);
      this.$set(this.form,'pointDesc',data.pointDesc);
      this.$set(this.form,'auditMatter',data.keynoteTitle);
      console.log(this.form);
    },
    openLawFunction(val) {
      this.TableLawVisible = true;
    },
    closeLawDialog(val) {
      if (val) this.$set(this.form, 'lawContent', val)
      this.TableLawVisible = false;
    },
    showProjectDialog() {
      this.$nextTick(() => {
        this.$refs.ChoseProject.initParams({
          isProjectApproved: true,//项目是否审批完成
          isEngineering: false,
          isTermination: false
        });
      })
    },
    handlePreview (file) {
      // console.log(file.url);
      const a = document.createElement('a');
      let url = file.url ? file.url : file.response.data.url;
     // let fileName = '你想要的文件名.docx'; // 这里设置你想要的文件名，包括扩展名
      a.setAttribute('download', file.name);
      a.setAttribute('href', url);
      a.click();
      // this.attachment.filePath = file.url ? file.url : file.response.data.url;
      // this.attachment.fileName = file.name;
      // let encodedPath = encodeURIComponent(this.attachment.filePath);
      // let encodedName = encodeURIComponent(this.attachment.fileName);
      // getSysFile(encodedPath,encodedName);
      // window.open(file.url ? file.url : file.response.data.url)
    },

    closeProjectDialog() {
      this.projectDialog = false
    },
    projectDataHandle(row){
      this.projectDialog = false
      this.$set(this.form,'projectId',row.projectId);
      this.$set(this.form,'projectName',row.projectName);
      console.log(this.form);
    },
    init(row){
      if (row){
        this.$set(this, "form", row);
        this.form.auditMatter = row.keynoteTitle;
      }
      this.dialog = true;
    },
    submit() {
      this.$refs['optForm'].validate((valid) => {
        if (valid) {
          this.loading = true;
          this.form.isEngineering = 0;
          submit(this.form).then((res) => {
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.cancelDialog();
          }, () => {
            this.loading = false;
          });
        } else {
          return false;
        }
      });
    },
    submitAudit() {
      this.$refs['optForm'].validate((valid) => {
        if (valid) {
          this.loading = true;
          this.form.isEngineering = 0;
          submitAudit(this.form).then((res) => {
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.cancelDialog();
          }, () => {
            this.loading = false;
          });
        } else {
          return false;
        }
      });
    },
    cancelDialog(){
      this.dialog = false;
      this.$emit('cancelDialog', {})
      this.$refs['optForm'].resetFields()
    },
    wordFileHandle(e) {
      this.$set(this.form, "wordFile", e.wordFile);
      this.$set(this.form, "rectifyId", e.id);
    }
  }
}
</script>
<style scoped>
.custom-textarea /deep/ textarea {
  font-size: 15px; /* 设置字体大小 */
  color: #333; /* 设置字体颜色 */
}
</style>
